/**
 * 
 */
package au.edu.swin.videoshop.posapp.ui.sections;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.ejb.EJB;

import au.edu.swin.videoshop.bean.Address;
import au.edu.swin.videoshop.bean.AddressState;
import au.edu.swin.videoshop.bean.Classification;
import au.edu.swin.videoshop.bean.Customer;
import au.edu.swin.videoshop.bean.MediumType;
import au.edu.swin.videoshop.bean.Rental;
import au.edu.swin.videoshop.bean.RentalStatus;
import au.edu.swin.videoshop.bean.Staff;
import au.edu.swin.videoshop.bean.StaffRole;
import au.edu.swin.videoshop.bean.Store;
import au.edu.swin.videoshop.bean.Title;
import au.edu.swin.videoshop.bean.TitleCategory;
import au.edu.swin.videoshop.bean.TitleCopy;
import au.edu.swin.videoshop.bean.TitleMedium;
import au.edu.swin.videoshop.service.CustomerService;
import au.edu.swin.videoshop.service.MiscUtil;
import au.edu.swin.videoshop.service.RentalService;
import au.edu.swin.videoshop.service.ReservationService;
import au.edu.swin.videoshop.service.StaffService;
import au.edu.swin.videoshop.service.StoreService;
import au.edu.swin.videoshop.service.TitleService;

/**
 * @author julie
 *
 */
public class TestSection implements Serializable {
	
	@EJB 
	private TitleService mTitleService;
	
	@EJB 
	private StoreService mStoreService;
	
	@EJB 
	private CustomerService mCustomerService;
	
	@EJB 
	private StaffService mStaffService;
	
	@EJB 
	private RentalService mRentalService;
	
	@EJB 
	private ReservationService mReservationService;
	
	public TestSection() {
		
	}
	
	
	private List mStores;
	private List mStaffs;
	private List mCustomers;
	private List mCopies;
	private Map mCopiesUnavailable;
	private List mCategories;

	/**
	 * @return the stores
	 */
	public List getStores() {
		return mStores;
	}

	/**
	 * @return the staffs
	 */
	public List getStaffs() {
		return mStaffs;
	}

	/**
	 * @return the customers
	 */
	public List getCustomers() {
		return mCustomers;
	}
	
	/**
	 * @return the copies
	 */
	public List getCopies() {
		return mCopies;
	}
	
	
	private static final String[] sRandomFirstName = new String[]{
		"Marry",
		"John",
		"Julie",
		"Andrew",
		"Julian",
		"William",
		"George",
		"Brad",
		"Ted",
		"Harry",
		"Ronald",
		"Crystal",
		"Katherine",
		"Elizabeth",
	};
	
	private static final String[] sRandomLastName = new String[]{
		"Smith",
		"Black",
		"White",
		"Brown",
		"Rose",
		"Lee",
		"Simpson",
		"Potter",
		"Peterson",
		"Paxton",
		"Hamilton"
	};
	
	private static final String[] sRandomStreetName = new String[]{
		"Queen",
		"King",
		"Victoria",
		"Elizabeth",
		"Henry",
		"William",
		"North",
		"South",
		"East",
		"West"
	};
	
	private static final String[] sRandomStreetStype = new String[]{
		"Street",
		"Road",
		"Avenue",
		"Place"
	};
	
	private static final String[] sRandomSuburb = new String[]{
		"Hawthorn",
		"Hawthorn East",
		"Carnegie",
		"Armadale",
		"Auburn",
		"Fountain Lake",
		"Box Hill",
		"Burwood",
		"Ashwood",
		"Newtown",
	};
	
	private static final AddressState[] sRandomState = new AddressState[]{
		AddressState.ACT,
		AddressState.NSW,
		AddressState.NT,
		AddressState.SA,
		AddressState.TAS,
		AddressState.VIC,
		AddressState.WA
	};
	
	private static final String[] sRandomDomain = new String[]{
		"yahoo.com",
		"gmail.com",
		"hotmail.com",
		"email.com",
		"xyz.com",
		"abc.com",
		"videoshop.com",
		"swin.edu.au"
	};
	
	
	private static int sSequenceId = 0;
	private static final Random sRandom = new Random();
	
	private int getRandomInt(int from, int to) {
		return sRandom.nextInt((to - from) + 1) + from;
	}
	
	private BigDecimal getRandomBigDecimal(float from, float to) {
		return new BigDecimal(sRandom.nextFloat() * ((to - from) + 1) + from);
	}
	
	private String getRandomString(String[] array) {
		return array[sRandom.nextInt(array.length)];
	}
	
	private Date getRandomDate(Date fromDate, Date toDate) {
		int days = MiscUtil.days(fromDate, toDate);
		int randomDay = sRandom.nextInt(days);
		
		Calendar cal = Calendar.getInstance();
		cal.setTime(fromDate);
		
		cal.add(Calendar.DATE, randomDay);
		
		return cal.getTime();
	}
	
	private Date getRandomDate(Date fromDate, int days) {
		int randomDay = sRandom.nextInt(days);
		
		Calendar cal = Calendar.getInstance();
		cal.setTime(fromDate);
		
		cal.add(Calendar.DATE, randomDay);
		
		return cal.getTime();
	}
	
	private String getRandomFirstName() {
		return getRandomString(sRandomFirstName);
	}
	
	private String getRandomLastName() {
		return getRandomString(sRandomLastName);
	}
	
	private String getRandomContactNumber() {
		StringBuilder number = new StringBuilder("04");
		
		for (int i= 0; i < 8; i++) {
			number.append(sRandom.nextInt(10));
		}
		
		return number.toString();
	}
	
	private String getRandomEmailAddress(String firstName, String lastName) {
		return firstName.toLowerCase() + "." + lastName.toLowerCase() + "@" + getRandomString(sRandomDomain);
	}
	
	private String getRandomUserName(String firstName, String lastName) {
		return firstName.toLowerCase() + sSequenceId++;
	}
	
	private String getRandomStreet() {
		return (sRandom.nextInt(1000) + 1) +  " " + getRandomString(sRandomStreetName) + " " + getRandomString(sRandomStreetStype);
	}
	
	private String getRandomSuburb() {
		return getRandomString(sRandomSuburb);
	}
	
	private String getRandomPostcode() {
		return (Integer.toString(sRandom.nextInt(10)) + 1) + Integer.toString(sRandom.nextInt(10)) + Integer.toString(sRandom.nextInt(10)) + Integer.toString(sRandom.nextInt(10));
	}
	
	private AddressState getRandomState() {
		return sRandomState[sRandom.nextInt(sRandomState.length)];
	}
	
	private Store getRandomStore() {
		return (Store)mStores.get(sRandom.nextInt(mStores.size()));
	}
	
	private Staff getRandomStaff() {
		return (Staff)mStaffs.get(sRandom.nextInt(mStaffs.size()));
	}
	
	private Customer getRandomCustomer() {
		return (Customer)mCustomers.get(sRandom.nextInt(mCustomers.size()));
	}
	
	private TitleCopy getRandomTitleCopy() {
		return (TitleCopy)mCopies.get(sRandom.nextInt(mCopies.size()));
	}

	private TitleCategory findCategory(String name) {
		for (Iterator i = mCategories.iterator(); i.hasNext();) {
			TitleCategory category = (TitleCategory) i.next();
			
			if (category.getCategoryName().equals(name)) {
				return category;
			}
		}
		
		return null;
	}
	
	private void generateTestTitleData(Title title) {
		List medidumTypeList = new ArrayList();

		medidumTypeList.add(MediumType.TAPE);
		medidumTypeList.add(MediumType.VCD);
		medidumTypeList.add(MediumType.DVD);
		medidumTypeList.add(MediumType.BLURAY);
		medidumTypeList.add(MediumType.HDDVD);
			

		for (Iterator i = medidumTypeList.iterator(); i.hasNext();) {
			MediumType mediumType = (MediumType) i.next();
			
			TitleMedium titleMedium = title.addMedium(mediumType);
			
			if (sRandom.nextBoolean()) {
				titleMedium.setMaxRentalPeriod(getRandomInt(10, 30));
				titleMedium.setRentalRate(getRandomBigDecimal(1, 3));
				titleMedium.setPenaltyRate(getRandomBigDecimal(3, 5));
				
				for (Iterator j = mStores.iterator(); j.hasNext();) {
					Store store = (Store) j.next();
					
					//Add to Store
					int numberOfCopies = getRandomInt(1, 3);
					
					for (int k = 0; k < numberOfCopies; k++) {
						String generatedId = (store.getStoreName().substring(0, 3) + k + (sSequenceId++)).toUpperCase();
						titleMedium.addCopy(generatedId, store);
					}
				}
			}
			else {
				titleMedium.setMaxRentalPeriod(0);
				titleMedium.setRentalRate(null);
				titleMedium.setPenaltyRate(null);
			}
		}
	}
	
	private Customer generateTestCustomerData() {
		Customer customer = new Customer();
		customer.setFirstName(getRandomFirstName());
		customer.setLastName(getRandomLastName());
		customer.setAddress(generateTestAddressData());
		customer.setContactNumber(getRandomContactNumber());
		customer.setEmailAddress(getRandomEmailAddress(customer.getFirstName(), customer.getLastName()));
		customer.setCredit(getRandomBigDecimal(0, 200));
		customer.setUserName(getRandomUserName(customer.getFirstName(), customer.getLastName()));
		customer.setPassword("xxx");

		return customer;
	}
	
	private Staff generateTestStaffData(Store store, List managers, StaffRole role) {
		Staff staff = new Staff();
		staff.setFirstName(getRandomFirstName());
		staff.setLastName(getRandomLastName());
		staff.setAddress(generateTestAddressData());
		staff.setContactNumber(getRandomContactNumber());
		staff.setEmailAddress(getRandomEmailAddress(staff.getFirstName(), staff.getLastName()));
		staff.setStore(store);
		if (managers != null) {
			staff.setSupervisor((Staff)managers.get(sRandom.nextInt(managers.size())));
		}
		
		staff.setUserName(getRandomUserName(staff.getFirstName(), staff.getLastName()));
		staff.setRole(role);
		staff.setPassword("xxx");

		return staff;
	}
	
	private Staff generateTestSeniorManagerData() {
		Staff staff = new Staff();
		staff.setFirstName(getRandomFirstName());
		staff.setLastName(getRandomLastName());
		staff.setAddress(generateTestAddressData());
		staff.setContactNumber(getRandomContactNumber());
		staff.setEmailAddress(getRandomEmailAddress(staff.getFirstName(), staff.getLastName()));
		staff.setStore(null);
		staff.setUserName("seniormanager");
		staff.setRole(StaffRole.SENIOR_MANAGER);
		staff.setPassword("xxx");
		
		return staff;
	}
	
	private Address generateTestAddressData() {
		Address address = new Address();
		
		address.setAddressLine(getRandomStreet());
		address.setSuburb(getRandomSuburb());
		address.setPostcode(getRandomPostcode());
		address.setState(getRandomState());
		
		return address;
	}



	public String populate() {
	
		Store store1 = new Store();
		store1.setStoreName("Hawthorn Store");
		store1.setAddress(new Address("235 Glenferrie Road", "Hawthorn", "3122", AddressState.VIC));
		
		Store store2 = new Store();
		store2.setStoreName("Melbourne CBD Store");
		store2.setAddress(new Address("134 LaTrobe Street", "Melbourne", "3000", AddressState.VIC));

		Store store3 = new Store();
		store3.setStoreName("Sydney CBD Store");
		store3.setAddress(new Address("753 Pitt Street", "Sydney", "2000", AddressState.VIC));

		Store store4 = new Store();
		store4.setStoreName("Canberra Store");
		store4.setAddress(new Address("75 Queen Street", "Canberra", "2034", AddressState.ACT));

		
		mStoreService.addStore(store1);
		mStoreService.addStore(store2);
		mStoreService.addStore(store3);
		mStoreService.addStore(store4);
	
		mStores = mStoreService.findAllStores();
		
		
		TitleCategory category1 = new TitleCategory();
		category1.setCategoryName("Action");
		category1.setDescription("Action films are a film genre where action sequences, such as fighting, stunts, car chases or explosions, take precedence over elements like characterization or complex plotting. The action typically involves individual efforts on the part of the hero, in contrast with most war films.");
		
		TitleCategory category2 = new TitleCategory();
		category2.setCategoryName("Adventure");
		category2.setDescription("adventure films are usually set in the past or sometimes in a fantasy world, and often involve swordfighting or swashbuckling.");
		
		TitleCategory category3 =new TitleCategory();
		category3.setCategoryName("Animation");
		category3.setDescription("Animation is the rapid display of a sequence of images of 2-D artwork or model positions in order to create an illusion of movement");
		
		TitleCategory category4 =new TitleCategory();
		category4.setCategoryName("Comedy");
		category4.setDescription("Comedy film is genre of film in which the main emphasis is on humor.");
		
		TitleCategory category5 =new TitleCategory();
		category5.setCategoryName("Documentary");
		category5.setDescription("Documentary is a broad category of visual expression that is based on the attempt, in one fashion or another, to \"document\" reality.");
		
		TitleCategory category6 =new TitleCategory();
		category6.setCategoryName("Drama");
		category6.setDescription("A drama film is a film that depends mostly on in-depth character development, interaction, and highly emotional themes. In a good drama film, the audience is able to experience what other characters are feeling and identify with someone.");
		
		TitleCategory category7 =new TitleCategory();
		category7.setCategoryName("Horror");
		category7.setDescription("of the horror genre that are designed to elicit fright, fear, terror, or horror from viewers. In horror film plots, evil forces, events, or characters, sometimes of supernatural origin, intrude into the everyday world.");
		
		TitleCategory category8 =new TitleCategory();
		category8.setCategoryName("Kung-fu");
		category8.setDescription("This genre is a type of action film characterized by extensive fighting scenes employing various types of martial arts.");
		
		TitleCategory category9 =new TitleCategory();
		category9.setCategoryName("Musical");
		category9.setDescription("The musical film is a film genre in which several songs sung by the characters are interwoven into the narrative.");
		
		TitleCategory category10 =new TitleCategory();
		category10.setCategoryName("Romance");
		category10.setDescription("Romance film can be loosely defined as any film in which the central plot (the premise of the story) revolves around the romantic involvement of the story's protagonists.");
		
		TitleCategory category11 =new TitleCategory();
		category11.setCategoryName("Sci-Fi");
		category11.setDescription("A genre of films that often involves speculations based on current or future science or technology.");
		
		TitleCategory category12 =new TitleCategory();
		category12.setCategoryName("War");
		category12.setDescription("The war film is a film genre concerned with warfare, usually about naval, air or land battles, sometimes focusing instead on prisoners of war, covert operations, military training or other related subjects.");

		mTitleService.addTitleCategory(category1);
		mTitleService.addTitleCategory(category2);
		mTitleService.addTitleCategory(category3);
		mTitleService.addTitleCategory(category4);
		mTitleService.addTitleCategory(category5);
		mTitleService.addTitleCategory(category6);
		mTitleService.addTitleCategory(category7);
		mTitleService.addTitleCategory(category8);
		mTitleService.addTitleCategory(category9);
		mTitleService.addTitleCategory(category10);
		mTitleService.addTitleCategory(category11);
		mTitleService.addTitleCategory(category12);
		
		mCategories = mTitleService.findAllCategories();
	
		
		TitleCategory actionCategory = findCategory("Action");
		TitleCategory adventureCategory = findCategory("Adventure");
		TitleCategory animationCategory = findCategory("Animation");
		TitleCategory comedyCategory = findCategory("Comedy");
		TitleCategory documentaryCategory = findCategory("Documentary");
		TitleCategory dramaCategory = findCategory("Drama");
		TitleCategory horrorCategory = findCategory("Horror");
		TitleCategory kungfuCategory = findCategory("Kung-fu");
		TitleCategory musicalCategory = findCategory("Musical");
		TitleCategory romanceCategory = findCategory("Romance");
		TitleCategory scifiCategory = findCategory("Sci-Fi");
		TitleCategory warCategory = findCategory("War");

		
		
		Title title1 = new Title();
		title1.setCategory(actionCategory);
		title1.setClassification(Classification.M);
		title1.setTitleName("The Italian Job");
		title1.setDescription("Based on a 1969 Michael Caine film of the same name, thieves plan to pull of the heist of their lives by creating Los Angeles largest traffic jam ever.");
		title1.setYear(2003);
		
		Title title2 = new Title();
		title2.setCategory(actionCategory);
		title2.setClassification(Classification.R);
		title2.setTitleName("Fight Club");
		title2.setDescription("In this movie Edward Norton is the narrator who suffers from a lack of sleep. He tries different ways to cure this, but he does not succeed. He does get some sleep, but his conditions rebounds back into it's original state when he meets a lovely young woman, whose name is Marla. He finds out that she and he both have a lot in common and they spend a lot of time together. While touring, he meets an enigmatic young man named Tyler and after a short conversation both become fast friends");
		title2.setYear(1999);
		
		Title title3 = new Title();
		title3.setCategory(actionCategory);
		title3.setClassification(Classification.M);
		title3.setTitleName("Die Hard");
		title3.setDescription("New York cop John McClane, who has been a cop for 11 years, has just arrived in Los Angeles on Christmas Eve. For the past six months, John's wife Holly and their two kids Lucy McClane and John McClane Jr have been living in Los Angeles without John. In New York, Holly had a good job that turned into a career, and Holly was promoted to a powerful position in the Nakatomi Corporation. The promotion called for Holly to move to Los Angeles to work in the Nakatomi Plaza, a 40 story building.");
		title3.setYear(1988);
		
		Title title4 = new Title();
		title4.setCategory(adventureCategory);
		title4.setClassification(Classification.MA);
		title4.setTitleName("Into the Wild");
		title4.setDescription("After graduating from Emory University, top student and athlete Christopher McCandless abandons his possessions, gave his entire $24,000 savings account to charity and hitchhiked to Alaska to live in the wilderness. Along the way, Christopher encounters a series of characters that shape his life.");
		title4.setYear(2007);
		
		Title title5 = new Title();
		title5.setCategory(adventureCategory);
		title5.setClassification(Classification.PG);
		title5.setTitleName("Ben-Hur");
		title5.setDescription("Judah Ben-Hur lives as a rich Jewish prince and merchant in Jerusalem at the beginning of the 1st century. Together with the new governor his old friend Messala arrives as commanding officer of the Roman legions. At first they are happy to meet after a long time but their different politic views separate them. During the welcome parade a brick falls down from Judah's house and barely misses the governor.");
		title5.setYear(1959);
		
		Title title6 = new Title();
		title6.setCategory(adventureCategory);
		title6.setClassification(Classification.PG);
		title6.setTitleName("Indiana Jones and the Last Crusade");
		title6.setDescription("Indiana Jones, famed adventurer and archaeologist acquires a diary that holds clues and a map with no names to find the mysterious Holy Grail- which was sent from his father, Dr. Henry Jones, in Italy. Upon hearing from a private collector, Walter Donavan, that the mission for the Holy Grail went astray with the disappearance of his father, Indiana Jones and museum curator Marcus Brody venture to Italy in search of Indy's father.");
		title6.setYear(1989);
		
		Title title7 = new Title();
		title7.setCategory(animationCategory);
		title7.setClassification(Classification.G);
		title7.setTitleName("Finding Nemo");
		title7.setDescription("Marlin (a clown fish) is a widower who only has his son Nemo left of his family after a predator attack. Years later, on Nemo's first day of school, he's captured by a scuba diver and taken to live in a dentist office's fish tank. Marlin and his new absent-minded friend Dory set off across the ocean to find Nemo, while Nemo and his tankmates scheme on how to get out of the tank before he becomes the dentist's niece's new pet.");
		title7.setYear(2003);

		Title title8 = new Title();
		title8.setCategory(animationCategory);
		title8.setClassification(Classification.G);
		title8.setTitleName("The Lion King");
		title8.setDescription("A young lion prince is born in Africa, thus making his uncle Scar the second in line to the throne. Scar plots with the hyenas to kill King Mufasa and Prince Simba, thus making himself King. The King is killed and Simba is led to believe by Scar that it was his fault, and so flees the kingdom in shame. After years of exile he is persuaded to return home to overthrow the usurper and claim the kingdom as his own thus completing the \"Circle of Life\".");
		title8.setYear(1994);
		
		Title title9 = new Title();
		title9.setCategory(comedyCategory);
		title9.setClassification(Classification.PG);
		title9.setTitleName("Monty Python and the Holy Grail");
		title9.setDescription("The movie starts out with Arthur, King of the Britons, looking for knights to sit with him at Camelot. He finds many knights including Sir Galahad the pure, Sir Lancelot the brave, the quiet Sir Bedevere, and Sir Robin the Not-Quite-So-Brave-as-Sir Lancelot. They do not travel on horses, but pretend they do and have their servants bang coconuts to make the sound of horse's hooves.");
		title9.setYear(1975);
		
		Title title10 = new Title();
		title10.setCategory(comedyCategory);
		title10.setClassification(Classification.G);
		title10.setTitleName("City Lights");
		title10.setDescription("A tramp falls in love with a beautiful blind girl. Her family is in financial trouble. The tramp's on-and-off friendship with a wealthy man allows him to be the girl's benefactor and suitor.");
		title10.setYear(1931);
		
		Title title11 = new Title();
		title11.setCategory(comedyCategory);
		title11.setClassification(Classification.PG);
		title11.setTitleName("Aquamarine");
		title11.setDescription("It's the end of summer and Claire (Emma Roberts) and Hailey (JoJo) have a major problem. In just five days, Hailey's family is moving halfway around the world!These girls need a major miracle, and they get one in the form of Aquamarine, a beautiful mermaid who washes ashore in a late summer storm.");
		title11.setYear(2007);
		
		Title title12 = new Title();
		title12.setCategory(dramaCategory);
		title12.setClassification(Classification.PG);
		title12.setTitleName("Step Up");
		title12.setDescription("A fun, hip, music driven summer film in the vein of Save the Last Dance. Set in the exhilarating world of music and dance, Step Up is an inspiring romantic drama that follows the struggles of two teenagers, Tyler and Nora, from opposite sides of the tracks, as they try to achieve their dreams");
		title12.setYear(2007);
		
		Title title13 = new Title();
		title13.setCategory(dramaCategory);
		title13.setClassification(Classification.M);
		title13.setTitleName("Pulp Fiction");
		title13.setDescription("Jules Winnfield and Vincent Vega are two hitmen who are out to retrieve a suitcase stolen from their employer, mob boss Marsellus Wallace. Wallace has also asked Vincent to take his wife Mia out a few days later when Wallace himself will be out of town. Butch Coolidge is an aging boxer who is paid by Wallace to lose his next fight. The lives of these seemingly unrelated people are woven together comprising of a series of funny, bizarre and uncalled-for incidents.");
		title13.setYear(1994);
		
		Title title14 = new Title();
		title14.setCategory(musicalCategory);
		title14.setClassification(Classification.G);
		title14.setTitleName("The Sound of Music");
		title14.setDescription("A woman leaves an Austrian convent to become a governess to a Naval officer widower.");
		title14.setYear(1965);
		
		Title title15 = new Title();
		title15.setCategory(scifiCategory);
		title15.setClassification(Classification.M);
		title15.setTitleName("The Matrix");
		title15.setDescription("A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against the controllers of it");
		title15.setYear(1999);
		
		Title title16 = new Title();
		title16.setCategory(scifiCategory);
		title16.setClassification(Classification.G);
		title16.setTitleName("2001 A Space Odyssey");
		title16.setDescription("Mankind finds a mysterious, obviously artificial, artifact buried on the moon and, with the intelligent computer HAL, sets off on a quest.");
		title16.setYear(1968);
		
		Title title17 = new Title();
		title17.setCategory(kungfuCategory);
		title17.setClassification(Classification.MA);
		title17.setTitleName("Kung fu");
		title17.setDescription("In Shanghai, China in the 1940s, a wannabe gangster aspires to join the notorious \"Axe Gang\" while residents of a housing complex exhibit extraordinary powers in defending their turf.");
		title17.setYear(2004);
		
		generateTestTitleData(title1);
		generateTestTitleData(title2);
		generateTestTitleData(title3);
		generateTestTitleData(title4);
		generateTestTitleData(title5);
		generateTestTitleData(title6);
		generateTestTitleData(title7);
		generateTestTitleData(title8);
		generateTestTitleData(title9);
		generateTestTitleData(title10);
		generateTestTitleData(title11);
		generateTestTitleData(title12);
		generateTestTitleData(title13);
		generateTestTitleData(title14);
		generateTestTitleData(title15);
		generateTestTitleData(title16);
		generateTestTitleData(title17);
		
		mTitleService.addTitle(title1);
		mTitleService.addTitle(title2);
		mTitleService.addTitle(title3);
		mTitleService.addTitle(title4);
		mTitleService.addTitle(title5);
		mTitleService.addTitle(title6);
		mTitleService.addTitle(title7);
		mTitleService.addTitle(title8);
		mTitleService.addTitle(title9);
		mTitleService.addTitle(title10);
		mTitleService.addTitle(title11);
		mTitleService.addTitle(title12);
		mTitleService.addTitle(title13);
		mTitleService.addTitle(title14);
		mTitleService.addTitle(title15);
		mTitleService.addTitle(title16);
		mTitleService.addTitle(title17);

		
		mCopies = mTitleService.findAllTitleCopies();
		
		for (int i = 0; i < 20; i++) {
			Customer customer = generateTestCustomerData();
			mCustomerService.addCustomer(customer);
		}
		
		mCustomers = mCustomerService.findAllCustomers();
		
		
		mStaffService.addStaff(generateTestSeniorManagerData());
		
		for (Iterator i = mStores.iterator(); i.hasNext();) {
			Store store = (Store) i.next();
			
			int numberOfStoreManager = getRandomInt(1, 2);
			for (int j = 0; j < numberOfStoreManager; j++) {
				Staff staff = generateTestStaffData(store, null, StaffRole.STORE_MANAGER);
				
				mStaffService.addStaff(staff);
			}
			
			List managers = mStaffService.findStaffsByStoreId(store.getStoreId());
			
			int numberOfClerks = getRandomInt(2, 5);
			for (int j = 0; j < numberOfClerks; j++) {
				Staff staff = generateTestStaffData(store, managers, StaffRole.CLERK);
				
				mStaffService.addStaff(staff);
			}
		}
		
		mStaffs = mStaffService.findAllStaffs();

		
		return null;
	}
	
	public String populateRental() {
		int randomCycle = getRandomInt(2, 5);
		
		for (int k = 0; k < randomCycle; k++) {
			for (Iterator i = mCopies.iterator(); i.hasNext();) {
				TitleCopy copy = (TitleCopy) i.next();
				Rental rental = mRentalService.makeRental(getRandomCustomer(), copy, getRandomStaff(), getRandomDate(MiscUtil.getDay(2006, 1, 1), new Date()));
				if (rental != null) {
					mRentalService.addRental(rental);
				}
			}
			
			List rentals = mRentalService.findAllRentals();
			
			for (Iterator i = rentals.iterator(); i.hasNext();) {
				Rental rental = (Rental) i.next();
				
				if (rental.getStatus() == RentalStatus.OPEN) {
					if (sRandom.nextBoolean()) { //Return
						
						Date returnDate = null;
						//Return before the due date
						if (sRandom.nextBoolean()) { 
							returnDate = getRandomDate(rental.getRentalDate(), rental.getDueDate());
						}
						//Return after the due date
						else {
							returnDate = getRandomDate(rental.getDueDate(), 30);
						}
						
						mRentalService.addReturn(rental.getRentalId(), returnDate);
					}
				}
			}
		}


		/*
		for (int i = 0; i < 100; i++) {
			Reservation reservation = new Reservation();
			
			Date reservationDate = getRandomDate(MiscUtil.getDay(2007, 1, 1), MiscUtil.getDay(2007, 12, 31));
			Date expiryDate =  getRandomDate(new Date(), MiscUtil.getDay(2007, 12, 31));
			TitleCopy copy = getRandomTitleCopy();
			
			reservation.setCustomer(getRandomCustomer());
			reservation.setReservationDate(reservationDate);
			reservation.setExpiryDate(expiryDate);
			reservation.setMedium(copy.getMedium());
			reservation.setStore(copy.getStore());
			
			mReservationService.addReservation(reservation);
		}
		
		
		*/
		
		return null;
	}


}



